package com.ruoyi.project.wx.service.impl;


import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.bootdo.PageHelperUtils;
import com.ruoyi.project.wx.dao.MemberExtractDao;
import com.ruoyi.project.wx.dao.OrderComDao;
import com.ruoyi.project.wx.domain.OrderComDO;
import com.ruoyi.project.wx.service.OrderComService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class OrderComServiceImpl implements OrderComService {
	@Autowired
	private OrderComDao orderComDao;
	@Autowired
	private MemberExtractDao memberExtractDao;
	
	@Override
	public OrderComDO get(String id){
		return orderComDao.get(id);
	}
	
	@Override
	public List<OrderComDO> list(Map<String, Object> map){
		return orderComDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return orderComDao.count(map);
	}
	
	@Override
	public int save(OrderComDO orderCom){
		return orderComDao.save(orderCom);
	}
	
	@Override
	public int update(OrderComDO orderCom){
		return orderComDao.update(orderCom);
	}
	
	@Override
	public int remove(String id){
		return orderComDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return orderComDao.batchRemove(ids);
	}

	@Override
	public Map<String,Object> getMemberCom(Map<String, Object> map) {
		//提现总金额
		BigDecimal extractMoney = memberExtractDao.getNumByUser(map);
		map.put("type","0");  //可用
		BigDecimal kPrice =  orderComDao.getMemberPrice(map).subtract(extractMoney);
		map.put("type","1");  //待结算
		BigDecimal dPrice =  orderComDao.getMemberPrice(map);
		map.put("type","2");  //总金额
		BigDecimal allPrice =  orderComDao.getMemberPrice(map).subtract(extractMoney);
		Map<String,Object> priceMap = new HashMap<>();
		priceMap.put("kPrice",kPrice);
		priceMap.put("dPrice",dPrice);
		priceMap.put("allPrice",allPrice);
		return priceMap;
	}

	@Override
	public PageInfo<Map<String,Object>> getMemberComList(Map<String, Object> paramMap) {
		PageHelperUtils.page(paramMap);
		List<Map<String,Object>> list = orderComDao.getMemberPriceList(paramMap);
		PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
		return pageInfo;
	}
	
}
